<template>
  <div class="container">
    <div class="header">
      <h1>孵化器季度情况监测表</h1>
    </div>

    <div class="form-group">

    </div>

    <table class="report-table" cellspacing="0" cellpadding="0" border="1">
      <colgroup>
        <col width="50%">
        <col width="50%">
      </colgroup>
      <tbody>
      <tr>  <td>企业名称：</td>
        <td class="company-name-value">{{ form.companyName ?? '&nbsp;' }}</td></tr>

      <tr>
        <td class="label-cell">本季度在孵企业获得投融资总额</td>
        <td class="value-cell">
          {{ form.currentFinance ?? '&nbsp;' }} <span class="unit">千元</span>
        </td>
      </tr>
      <tr>
        <td class="label-cell">在孵企业从业人员数量</td>
        <td class="value-cell">
          {{ form.employees ?? '&nbsp;' }} <span class="unit">人</span>
        </td>
      </tr>
      <tr>
        <td class="label-cell">其中：吸纳应届大学毕业生数量</td>
        <td class="value-cell">
          {{ form.freshGraduates ?? '&nbsp;' }} <span class="unit">人</span>
        </td>
      </tr>
      <tr>
        <td class="label-cell">是否为教师创办企业</td>
        <td class="value-cell radio-cell">
          <div class="radio-display">
            <span class="radio-icon" :class="{selected: form.teacherFounded === 1}">●</span>
            <span>是</span>
          </div>
          <div class="radio-display">
            <span class="radio-icon" :class="{selected: form.teacherFounded === 0}">●</span>
            <span>否</span>
          </div>
        </td>
      </tr>
      <tr>
        <td class="label-cell">是否为大学生创办企业</td>
        <td class="value-cell radio-cell">
          <div class="radio-display">
            <span class="radio-icon" :class="{selected: form.studentFounded === 1}">●</span>
            <span>是</span>
          </div>
          <div class="radio-display">
            <span class="radio-icon" :class="{selected: form.studentFounded === 0}">●</span>
            <span>否</span>
          </div>
        </td>
      </tr>
      <tr>
        <td class="label-cell">成果转化总数</td>
        <td class="value-cell">
          {{ form.transferCount ?? '&nbsp;' }} <span class="unit">个</span>
        </td>
      </tr>
      <tr>
        <td class="label-cell">其中：依托高校数量</td>
        <td class="value-cell">
          {{ form.universityCount ?? '&nbsp;' }} <span class="unit">个</span>
        </td>
      </tr>
      <tr>
        <td class="label-cell">产出成果数</td>
        <td class="value-cell">
          {{ form.outputCount ?? '&nbsp;' }} <span class="unit">个</span>
        </td>
      </tr>
      <tr>
        <td class="label-cell">本季度专利申请数</td>
        <td class="value-cell">
          {{ form.patentApply ?? '&nbsp;' }} <span class="unit">件</span>
        </td>
      </tr>
      <tr>
        <td class="label-cell">其中：发明专利</td>
        <td class="value-cell">
          {{ form.inventionApply ?? '&nbsp;' }} <span class="unit">件</span>
        </td>
      </tr>
      <tr>
        <td class="label-cell">企业所拥有有效知识产权数</td>
        <td class="value-cell">
          {{ form.validIp ?? '&nbsp;' }} <span class="unit">件</span>
        </td>
      </tr>
      <tr>
        <td class="label-cell">其中：发明专利</td>
        <td class="value-cell">
          {{ form.validInvention ?? '&nbsp;' }} <span class="unit">件</span>
        </td>
      </tr>
      </tbody>
    </table>

    <div class="footer">
      <button @click="printPage" class="print-btn">打印</button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { reactive, onMounted } from 'vue';
import { useRoute } from 'vue-router';
import { GetDataHatchQuarterid } from '@/api/enterpeise';

const route = useRoute();
const form = reactive({
  companyName: '',
  currentFinance: null as number | null,
  employees: null as number | null,
  freshGraduates: null as number | null,
  teacherFounded: null as number | null,
  studentFounded: null as number | null,
  transferCount: null as number | null,
  universityCount: null as number | null,
  outputCount: null as number | null,
  patentApply: null as number | null,
  inventionApply: null as number | null,
  validIp: null as number | null,
  validInvention: null as number | null
});

const printPage = () => {
  window.print();
};

const fetchReportData = async (id: number) => {
  try {
    const res = await GetDataHatchQuarterid(id);
    if (res.code === 200) {
      console.log(res.data);
      Object.assign(form, res.data);
    }
  } catch (error) {
    console.error('获取报表数据失败:', error);
  }
};

onMounted(() => {
  const id = route.query.id;
  if (id) {
    fetchReportData(Number(id));
  }
});
</script>

<style scoped>
.container {
  width: 21cm;
  min-height: 29.7cm;
  margin: 0 auto;
  padding: 2cm;
  font-family: "SimSun", "宋体", serif;
  position: relative;
  background-color: white;
}

.header {
  text-align: center;
  margin-bottom: 20px;
}

.header h1 {
  font-size: 22px;
  font-weight: bold;
  margin: 0;
}

.form-group {
  margin-bottom: 20px;
  display: flex;
  align-items: center;
}

.company-name-value {
  margin-left: 10px;
  flex-grow: 1;
  border-bottom: 1px solid #000;
  min-height: 1em;
  padding: 0 10px;
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid #000;
  margin-bottom: 30px;
}

.report-table td {
  border: 1px solid #000;
  padding: 8px 12px;
  height: 40px;
  vertical-align: middle;
}

.label-cell {
  font-weight: bold;
  text-align: left;
}

.value-cell {
  text-align: left;
}

.unit {
  margin-left: 5px;
}

.radio-cell {

  align-items: center;
}

.radio-display {
  display: flex;
  align-items: center;
  margin-right: 30px;
}

.radio-icon {
  display: inline-block;
  width: 16px;
  height: 16px;
  line-height: 16px;
  text-align: center;
  margin-right: 5px;
  color: transparent;
  font-size: 16px;
}

.radio-icon.selected {
  color: #000;
}

.footer {
  display: flex;
  justify-content: center;
  margin-top: 30px;
}

.print-btn {
  padding: 8px 20px;
  background: #f5f5f5;
  border: 1px solid #d9d9d9;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
}

@media print {
  .footer {
    display: none;
  }

  .container {
    padding: 0;
    width: 100%;
  }

  .report-table {
    border: 1px solid #000 !important;
  }

  .report-table td {
    border: 1px solid #000 !important;
  }
}
</style>
